using System;
using System.ComponentModel;
using System.Reflection;
using util.EnumExtion;

namespace util.EnumExtion
{
    /// <summary>
    /// apiController分组
    /// </summary>
    public enum ApiGroupNameEnum
    {
        [Description("单例模式")]
        Singleton = 1,
        [Description("简单工厂")]
        SimpleFacotry = 2,
        [Description("工厂方法")]
        FacotryMethod = 3,
        [Description("抽象工厂")]
        AbstractFactory = 4,
    }

    public static class ApiGroupNameEnumExtension
    {
         public static string GetDescription(this ApiGroupNameEnum enumName)
        {
           try
           {
               string _description = string.Empty;
               FieldInfo _fieldInfo = enumName.GetType().GetField(enumName.ToString());
               DescriptionAttribute[] _attributes = _fieldInfo.GetDescriptAttr();
               if (_attributes != null && _attributes.Length > 0)
                   _description = _attributes[0].Description;
               else
                   _description = null;//enumName.ToString();
               return _description;
           }
           catch (Exception ex)
           {
               System.Console.WriteLine(ex.ToString());
               return null;
           }            
        }
    }
}